<?php
/**
 * @package contenite
 */
if (intval(PHP_VERSION) < 5) {
  die('This site only works with <a href="http://gophp5.org/" target="_blank">PHP5</a>');
}

/*
 * Add a trailing slash to URLs ending in a directory
 * so that relative path names will work in stacked apps
 */
if ($_SERVER['REQUEST_METHOD'] == 'GET' && preg_match('#([^/]+)$#', $_SERVER['REQUEST_URI'], $matches)) {
  if (strpos($matches[1], '.') === FALSE) {
    // no extension
    header('Location: ' . $_SERVER['REQUEST_URI'] . '/');
    exit();
  }
}

global $config;
$config['root_dir'] = dirname(__FILE__);

$config['contenite_dir'] = class_exists('contenite_stream') 
  ? 'contenite:/' : realpath(dirname(__FILE__) . '/../contenite');

$config['root'] = '';

set_include_path($config['root_dir'] . PATH_SEPARATOR . get_include_path());

require_once 'config.php';
require_once $config['contenite_dir'] . '/lib.php';

if (!isset($_GET['q'])) {
  $_GET['q'] = '';
}

apps();

// Now that we have the complete include path we can load the session class
if (isset($config['session'])) {
  load($config['session']);
}
session_start();

route($_GET['q']);
